<template>
	<view class="waitingList_container">
		<view class="" style="height: 160rpx;">
		<view class="mail_List fixed z_ninetynine">
			<view class="mail" style="font-weight: 700;">
				<view class="order">巡更详情</view>
			</view>
		</view>
		<view class="icon fixed z_ninetynine">
			<u-icon name="arrow-left" color="#fefefe" size="40" @click="navigateBack"></u-icon>
		</view>
			
		</view>
		<!-- 执行信息 -->
		<view class="data_Statistics" style="padding: 44rpx 24rpx 0 ;">
			<text style="font-weight: 700; font-size: 30rpx; color: #c4c4c4;">丨</text><text
				style="font-weight: 700; font-size: 30rpx;">执行信息</text>
		</view>
		<view class="card" style="padding: 0 42rpx;">
			<u-form :model="form" ref="uForm">
				<u-form-item label="执行人:">
					<u-input v-model="form.Reporter"
						placeholder-style="color: #000; text-align: right; font-weight: 600;" :placeholder="particulars.staffName"
						:clearable="false" :disabled="true" />
				</u-form-item>
				<u-form-item label="执行状态:">
					<u-input v-model="form.address"
						placeholder-style="color: #000; text-align: right; font-weight: 600;" placeholder="待接单"
						:clearable="false" :disabled="true" v-if="particulars.patrolStatus=='0'" />
						<u-input v-model="form.address"
							placeholder-style="color: #000; text-align: right; font-weight: 600;" placeholder="待执行"
							:clearable="false" :disabled="true" v-if="particulars.patrolStatus=='1'" />
							<u-input v-model="form.address"
								placeholder-style="color: #000; text-align: right; font-weight: 600;" placeholder="完成"
								:clearable="false" :disabled="true" v-if="particulars.patrolStatus=='2'" />
								<u-input v-model="form.address"
									placeholder-style="color: #000; text-align: right; font-weight: 600;" placeholder="超时完成"
									:clearable="false" :disabled="true" v-if="particulars.patrolStatus=='3'" />
				</u-form-item>
				<u-form-item label="接单时间:" v-if="image==2&&current5==2">
					<u-input v-model="form.Reporter"
						placeholder-style="color: #000; text-align: right; font-weight: 600;" :placeholder="particulars.updateTime"
						:clearable="false" :disabled="true"  />
				</u-form-item>
			</u-form>
		</view>
		<!-- 巡更信息 -->
		<view class="data_Statistics" style="padding: 28rpx 24rpx 0 ;">
			<text style="font-weight: 700; font-size: 30rpx; color: #c4c4c4;">丨</text><text
				style="font-weight: 700; font-size: 30rpx;">巡更信息</text>
		</view>
		<view class="card" style="padding: 0 42rpx;">
			<u-form :model="form" ref="uForm">
				<u-form-item label="巡更路线名称:">
					<u-input v-model="form.Reporter"
						placeholder-style="color: #000; text-align: right; font-weight: 600;" :placeholder="particulars.patrolName"
						:clearable="false" :disabled="true" />
				</u-form-item>
				<u-form-item label="路线有效时间:">
					<u-input v-model="form.address"
						placeholder-style="color: #000; text-align: right; font-weight: 600;"
						:placeholder="particulars.beginTime+': 00 :00'" :clearable="false" :disabled="true" />
				</u-form-item>
				<u-form-item label="路线失效时间:">
					<u-input v-model="form.address"
						placeholder-style="color: #000; text-align: right; font-weight: 600;"
						:placeholder="particulars.endTime+': 00 :00'" :clearable="false" :disabled="true" />
				</u-form-item>
				<!-- <u-form-item label="巡更频率:"> -->
				<view class="frequency">
					<text style="line-height: 67rpx;">巡更频率:</text>
					<u-input v-model="form.address"
						placeholder-style="color: #000; text-align: right; font-weight: 600;"
						:placeholder="particulars.duration+'分钟巡更一次，允许超时10分钟'" :clearable="false" :disabled="true" />
				</view>
				<!-- </u-form-item> -->
				<view class="" v-if="patrol_two">
					<u-input v-model="form.address" placeholder-style="color: #000; text-align: right; font-weight: 600;"
						:placeholder="beginTime+': 00: 00'+' 至 '+patrol_two+': 00: 00'" :clearable="false" :disabled="true" />
					<u-input v-model="form.address" placeholder-style="color: #000; text-align: right; font-weight: 600;"
						:placeholder="patrol_two+': 00: 00'+' 至 '+endTime+': 00: 00'" :clearable="false" :disabled="true" />
				</view>
				<view class="" v-if="patrol_three">
					<u-input v-model="form.address" placeholder-style="color: #000; text-align: right; font-weight: 600;"
						:placeholder="beginTime+': 00: 00'+' 至 '+patrol_three+': 30: 00'" :clearable="false" :disabled="true" />
					<u-input v-model="form.address" placeholder-style="color: #000; text-align: right; font-weight: 600;"
						:placeholder="patrol_three+': 30: 00'+' 至 '+endTime+': 00: 00'" :clearable="false" :disabled="true" />
				</view>
				<view class="example">
					<text style="font-size: 24rpx;flex: 1; color: #ccc;">例如:</text>
					<view style="flex: 6;font-size: 24rpx; color: #ccc;">60分钟巡更一次，允许超时10分钟，即巡更总时长为60分钟,前50分钟为正常，后10分钟为超时
					</view>
				</view>
<!-- 				<u-form-item label="打卡规则:">
					<u-input v-model="form.address"
						placeholder-style="color: #000; text-align: right; font-weight: 600;" :placeholder="particulars.patrolStatus=='1'? '顺序' : '无序'"
						:clearable="false" :disabled="true" />
				</u-form-item> -->
			</u-form>
		</view>
	<!-- 巡更路线信息 -->
	<view class="order_Allocation">
		<view class="data_Statistics" style="padding: 28rpx 24rpx 0 ;">
			<text style="font-weight: 700; font-size: 30rpx; color: #c4c4c4;">丨</text><text
				style="font-weight: 700; font-size: 30rpx;">巡更路线信息</text>
		</view>
		<view class="card" style="position: relative; padding: 0 42rpx;">
			<u-form :model="form" ref="uForm">
				<!-- 巡更点1 -->
				<u-form-item :label="details.dotName" label-position="top">
							<view class="name" style="display: flex;">
								<text>巡点名称: </text>
								<u-input v-model="form.dotName" placeholder-style="color: #000; margin-left: 20rpx; "
									:placeholder="particulars.dotName" :clearable="false" :disabled="true" />
							</view>
<!-- 					<view class="position" style="display: flex;">
						<text>蓝牙位置: </text>
						<u-input v-model="form.describe" placeholder-style="color: #000; margin-left: 20rpx; "
							:placeholder="details.content" :clearable="false" :disabled="true" style="flex: 2;" />
					</view> -->
							<view class="points" style="display: flex;">
								<text>巡更要点: </text>
								<view class="main" style="margin-left: 20rpx; flex: 2;">
									<u-input v-model="form.describe" placeholder-style="color: #000;  "
										:placeholder="particulars.content" :clearable="false" :disabled="true" />
		<!-- 							<u-input v-model="form.describe" placeholder-style="color: #000; "
										placeholder="2、访春园Y20#-1单元门口围栏是否破损" :clearable="false" :disabled="true" />
									<u-input v-model="form.describe" placeholder-style="color: #000; "
										placeholder="3、访春园Y20#-1单元门口植物是否伸出" :clearable="false" :disabled="true" /> -->
								</view>
							</view>
				</u-form-item>
				<!-- 巡更点1异常上报 -->
<!-- 					<view class="position" style="display: flex;padding: 10rpx 0 20rpx 31rpx;border-bottom: 1px solid #f6f7f9;" v-if="flag4">
						<text style="color: red;line-height: 70rpx;">异常上报: </text>
						<u-input v-model="form.chargePerson" :custom-style="{'margin-left': '21rpx'}"
							placeholder="请输入异常情况" style="flex: 2;" />
					</view> -->
					<view class="" style="display: flex;justify-content: space-evenly; color: green; padding: 20rpx 0 36rpx;border-bottom: 1px solid #f6f7f9;" v-if="flag4">
						异常
					</view>
					<!-- 巡更点1按钮 -->
					<view class="" style="display: flex;justify-content: space-evenly; padding: 20rpx 0 36rpx; border-bottom: 1px solid #f6f7f9;" v-if="current4==2">
						<u-button type="error" :plain="true" size="mini" shape="circle" @click="reporting4">异常上报</u-button>
						<u-button type="success" size="mini" shape="circle" @click="normal">正常</u-button>
					</view>
					<!-- 巡更点1无异常 -->
					<view class="" style="display: flex;justify-content: space-evenly; color: green; padding: 20rpx 0 36rpx;border-bottom: 1px solid #f6f7f9;" v-if="abnormality3==2">
						无异常
					</view>
					<!-- 巡更点2异常上报 -->
<!-- 					<view class="position" style="display: flex;padding: 10rpx 0 20rpx 31rpx;border-bottom: 1px solid #f6f7f9;" v-if="flag3">
						<text style="color: red;line-height: 70rpx;">异常上报: </text>
						<u-input v-model="form.Executor" :custom-style="{'margin-left': '21rpx'}"
							placeholder="请输入异常情况" style="flex: 2;" />
					</view> -->
					<!-- 巡更点2按钮 -->
<!-- 					<view class="" style="display: flex;justify-content: space-evenly;padding: 20rpx 0 36rpx;border-bottom: 1px solid #f6f7f9;" v-if="current3==2">
						<u-button type="error" :plain="true" size="mini" shape="circle" @click="reporting3">异常上报</u-button>
						<u-button type="success" size="mini" shape="circle" @click="normal2">正常</u-button>
					</view> -->

				<!-- 巡更点3异常上报 -->
<!-- 					<view class="position" style="display: flex;padding: 10rpx 0 20rpx 31rpx;border-bottom: 1px solid #f6f7f9;" v-if="flag2">
						<text style="color: red;line-height: 70rpx;">异常上报: </text>
						<u-input v-model="form.Maintenance" :custom-style="{'margin-left': '21rpx'}"
							placeholder="请输入异常情况" style="flex: 2;" />
					</view> -->
					<!-- 巡更点3按钮 -->
<!-- 					<view class="" style="display: flex;justify-content: space-evenly;padding: 20rpx 0 36rpx;border-bottom: 1px solid #f6f7f9;" v-if="current2==2">
						<u-button type="error" :plain="true" size="mini" shape="circle" @click="reporting2">异常上报</u-button>
						<u-button type="success" size="mini" shape="circle" @click="normal3">正常</u-button>
					</view> -->
					<!-- 巡更点3无异常 -->
<!-- 					<view class="" style="display: flex;justify-content: space-evenly; color: green; padding: 20rpx 0 36rpx;border-bottom: 1px solid #f6f7f9;" v-if="abnormality==2">
						无异常
					</view> -->

					<!-- 巡更点4异常上报 -->
<!-- 					<view class="position" style="display: flex;padding: 10rpx 0 20rpx 31rpx;border-bottom: 1px solid #f6f7f9;" v-if="flag1">
						<text style="color: red;line-height: 70rpx;">异常上报: </text>
						<u-input v-model="form.end" :custom-style="{'margin-left': '21rpx'}"
							placeholder="请输入异常情况" style="flex: 2;" /> 
					</view> -->
					<!-- 巡更点4按钮 -->
<!-- 					<view class="" style="display: flex;justify-content: space-evenly;padding: 20rpx 0 36rpx;border-bottom: 1px solid #f6f7f9;" v-if="current==2">
						<u-button type="error" :plain="true" size="mini" shape="circle" @click="reporting1">异常上报</u-button>
						<u-button type="success" size="mini" shape="circle" @click="normal4">正常</u-button>
					</view> -->
					<!-- 巡更点4无异常 -->
<!-- 					<view class="" style="display: flex;justify-content: space-evenly; color: green; padding: 20rpx 0 36rpx;border-bottom: 1px solid #f6f7f9;" v-if="abnormality2==2">
						无异常
					</view> -->
			</u-form>
		</view>
	</view>
		<view class="button">
			<u-button type="primary" style="flex: 1;" v-if="current5==1" @click="receiving">接单</u-button>
			<u-button type="success" style="flex: 1;" v-if="current5==1" @click="Transfer">转交</u-button>
			<u-button type="primary" style="flex: 1;" @click="resolved" v-if="current5==2">执行</u-button>
			<!-- <u-button type="primary" style="flex: 1;" @click="resolved" v-if="current==2">提交</u-button> -->
			<u-button type="success" style="flex: 1;" @click="Approved" v-if="current5==3">提交</u-button>
		</view>
		<u-popup v-model="show" mode="center" width="626rpx" height="430rpx" border-radius="20">
			<view
				style="height: 54rpx; line-height: 54rpx; font-weight: 600; color: #a1a1a1; background-color: #fbfbfb; text-align: center;">
				巡更打卡提示</view>
			<view class="work_Order">
				<view class="work_Order_top"></view>
				<view class="work_Order_bottom" style="margin-top: 10rpx;">请在巡更位置打卡！</view>
			</view>
		</u-popup>
		<u-modal v-model="homepage" :show-cancel-button="true" :content="content" width="626rpx" height="430rpx" border-radius="20" @confirm="confirm">
<!-- 			<view
				style="height: 54rpx; line-height: 54rpx; font-weight: 600; color: #a1a1a1; background-color: #fbfbfb; text-align: center;">
				提示</view>
			<view class="work_Order">
				<view class="work_Order_top"></view>
				<view class="work_Order_bottom" style="margin-top: 10rpx;">退出后操作的内容会清空，是否继续</view>
			</view> -->
		</u-modal>
		<!-- 弹框 -->
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				// form表单
				form: {
					Reporter: '',
					title: '',
					address: '',
					describe: '',
					chargePerson: '',
					Executor: '',
					Maintenance: '',
					end: ''
				},
				// 演示地址，请勿直接使用
				action: 'http://www.example.com/upload',
				flag: 1,
				// 巡更点异常上报
				flag1: false,
				flag2: false,
				flag3: false,
				flag4: false,
				// 控制弹框
				show:false,
				// 控制巡更点按钮
				current:1,
				current2:1,
				current3:1,
				current4:1,
				// 控制底部按钮
				current5:2,
				// 控制接单时间
				image:2,
				// 控制巡更点无异常
				abnormality:1,
				abnormality2:1,
				abnormality3:1,
				// 模态框
				content:'退出后操作的内容会清空，是否继续',
				homepage:false,
				// 5秒后跳转的变量
				variable:false,
				// 待接单接单Id
				patrolId:'',
				// 车辆详情
				particulars:'',
				details:'',
				// 审核通过
				staff:'',
				// 巡更频率
				patrol:'',
				// 不带小数点的巡更频率
				patrol_two:'',
				// 带小数点的巡更频率
				patrol_three:'',
				beginTime:'',
				endTime:'',
				id:''
			}
		},
		onLoad(val) {
			this.loginId = uni.getStorageSync("setModel")
			console.log(val)
			if(val.patrolId){
			this.patrolId=val.patrolId
				// 待接单详情
				this.Details()
			}
			// this.loading()
		},
		methods: {
			// 待接单详情
			Details() {
				this.$http.get('Patrol/getPatrolById',{patrolId:this.patrolId}).then(res => {
					this.particulars=res.data
					let beginTime =parseFloat(res.data.beginTime.substring(11))
					let endTime =parseFloat(res.data.endTime.substring(11))
					let patrol = (beginTime + endTime)/2
					this.beginTime=res.data.beginTime.substring(11)
					this.endTime=res.data.endTime.substring(11)
					this.id=res.data.id
					this.patrol = patrol.toString()
					// console.log(beginTime)
					// console.log(endTime)
					// console.log(this.patrol,'---------------------------')
					let self = this
					// debugger
					if(self.patrol.length=='1') {
						// console.log('selfselfselfselfselfselfselfselfselfself')
						self.patrol_two='0' + self.patrol
						// console.log(self.patrol_two)
						
					} else if (self.patrol.indexOf(".")!='-1') {
						console.log('selfselfselfselfselfselfselfselfselfself')
						if(self.patrol.length=='3') {
							this.patrol_three='0' +parseInt(self.patrol)
						} else {
							this.patrol_three=parseInt(self.patrol)
						}
						// console.log(self.patrol_three)
					} else {
						self.patrol_two=self.patrol
					}
					console.log(res)
					// this.owners = res.data
				})
			},
			// 点击接单触发
			receiving() {
				// 待接单接单详情
				this.getListVehicleByIds()
				this.image=2
				this.current5 = 2
			},
			// 待接单接单详情
			getListVehicleByIds() {
				this.$http.put('PatrolStatus/updatePatrollingRouteStatus',{id:this.id}).then(res => {
					// this.particulars=res.data
					console.log(res, '待接单接单详情-------------')
				this.ordersDetails()
					// this.owners = res.data
				})
			},
			// 巡更接单时间详情
			ordersDetails() {
				this.$http.get('PatrolStatus/getPatrolRouteToBeExecutedById',{id:this.id,loginId:this.loginId.userId}).then(res => {
					this.particulars=res.data
					console.log(res, '巡更接单时间详情')
					// this.owners = res.data
				})
			},
			// 点击执行触发
			resolved() {
				this.image=3,
				this.current = 2,
				this.current2 = 2,
				this.current3= 2,
				this.current4 = 2,
				this.current5 = 3
			},
			// 点击异常上报触发
			reporting1() {
				// console.log(111)
				this.current = 1
				this.flag1 = true
			},
			// 点击异常上报触发
			reporting2() {
				this.current2 = 1
				this.flag2 = true
			},
			// 点击异常上报触发
			reporting3() {
				this.current3 = 1
				this.flag3 = true
			},
			// 点击异常上报触发
			reporting4() {
				// this.abnormalReporting()
				this.$http.put('Patrol/updateStatus',{id:this.id}).then(res => {
					// this.particulars=res.data
					// let that =this
					if(res.code==200) {
						this.$refs.uToast.show({
							title: res.msg,
						})
						this.current4 = 1
						this.flag4 = true
					} else {
						this.$refs.uToast.show({
							title: res.msg,
						})
					}
					console.log(res, '点击异常上报触发')
					// this.owners = res.data
				})
			},
			// abnormalReporting() {

			// },
			// 点击正常按钮触发
			normal() {
				this.current4=1
				this.abnormality3=2
			},
			// 点击正常按钮触发
			normal2() {
				this.show=true
			},
			// 点击正常按钮触发
			normal3() {
				this.current2=1
				this.abnormality=2
			},
			// 点击正常按钮触发
			normal4() {
				this.current=1
				this.abnormality2=2
			},
			// 点击提交按钮触发
			Approved() {
				if((this.form.chargePerson!=''||this.abnormality3==2)&&(this.form.Maintenance!=''||this.abnormality==2)&&(this.form.end!=''||this.abnormality2==2)) {
					this.image=4
					this.current5=6
					console.log(111)
				}
				// 提交工单
				this.$http.put('Patrol/updatePatrol',{patrolId:this.patrolId}).then(res => {
					// this.particulars=res.data
					console.log(res, '提交工单')
					// this.owners = res.data
					uni.navigateBack()
				})
			},
			// 点击转交按钮触发
			Transfer() {
				console.log(111)
				this.openUrl('/pages/workSecurity/securityImplemented/securityTransfer/securityTransfer')
			},
			// 点击返回按钮触发
			navigateBack() {
				// if(this.form.chargePerson!=''||this.abnormality3==2||this.form.Maintenance!=''||this.abnormality==2||this.form.end!=''||this.abnormality2==2) {
				// 	this.homepage=true
				// 	setTimeout(()=>{
				// 		this.variable=true
				// 	}, 5000)
				// }else {
				// }
					uni.navigateBack()
			},
			confirm() {
				if(this.variable==true) {
				this.openUrl('/pages/workSecurity/workSecurity')
				// console.log(11)
				} else {
					this.homepage=true
				}
			}		
		}
	}
</script>

<style lang="scss" scoped>
	.waitingList_container {
		.mail_List {
			overflow: hidden;
			width: 100%;
			background-color: #f2f2f2;

			.mail {
				padding: 10rpx 0;
				// margin-top: 96rpx;
				color: #999999;
				font-size: 40rpx;
				background-color: #e5e5e5;
			}

			.order {
				text-align: center;
			}
		}

		/deep/.card {
			.u-form-item--left {
				flex: unset !important;
				width: unset !important;
			}

			.frequency {
				display: flex;

				// justify-content: space-between;
				u-input {
					flex: 2;
				}
			}

			.example {
				display: flex;
				margin-left: 67rpx;
			}

			.u-form-item--right {
				margin-left: 31rpx;
			}
			button {
				width: 170rpx;
				border-radius: 100rpx!important;
			}
		}

		.icon {
			position: absolute;
			top: 18rpx;
			// top: 114rpx;
			left: 20rpx;
		}

		.second_card {
			.u-cell {
				padding: 18rpx 32rpx;

				/deep/.u-cell__value {
					color: #333333;
					font-weight: 600;
				}
			}

			/deep/.uni-card__content {
				padding: 16rpx 24rpx;
			}
		}
		
		// .order_Allocation {
		// 	/deep/button {
		// 		width: 170rpx;
		// 	}
		// }
		
		/deep/button {
			border-radius: unset !important;
		}

		.uni-border[data-v-19622063]:after {
			border: unset;
		}

		/deep/.uni-border.data-v-19622063:after {
			border: unset;
		}

		.slot-btn__hover {
			background-color: rgb(235, 236, 238);
		}

		.button {
			display: flex;
			// position: fixed;
			// left: 0;
			// right: 0;
			// bottom: 0;
			margin-top: 200rpx;
			border-radius: 14rpx;
			overflow: hidden;
			z-index: 9;

			.u-btn {
				border-radius: unset;
			}
		}

		.work_Order {
			margin-top: 60rpx;
			text-align: center;

			.work_Order_top {
				width: 168rpx;
				height: 168rpx;
				margin: 0 auto;
				background-color: #e5e5e5;
				border-radius: 50%;
			}
		}
	}
</style>
